#include "stdafx.h"
#include "NaviPathListStatu.h"
#include "NaviPathStatu.h"


CNaviPathListStatu::~CNaviPathListStatu(void)
{
}
//-------------------------------------------
void CALLBACK SDCardTimerNaviPathProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
	static bool sdcardExsist = CGenericFun::SDCardExsist();
	//CNaviPathListStatu* pStatu = (CNaviPathListStatu*)GRAPHICMGR.GetStatu(L"listview_NaviPathList");
	if (sdcardExsist != CGenericFun::SDCardExsist())
	{
		sdcardExsist = !sdcardExsist; 
		//pStatu->reLoadList();
	}
}


CNaviPathListStatu::CNaviPathListStatu(WCHAR* name):IStatu(name)
{

m_nIndexPos=1;


}


bool CNaviPathListStatu::ExitStatu()
{
	m_strDirPath = GlobalStatic::m_strCurrentDir;
	KillTimer(GRAPHICMGR.GetWnd(),SDCARD_TIMEER);
	return true;
}
bool CNaviPathListStatu::EnterStatu()
{
	CListBox *p = (CListBox*)GRAPHICMGR.GetElement(L"listview_NaviPathList");

	m_veFilter.push_back(L"exe");


	p->SetExtName(&m_veFilter);

p->SetCurDir(L"storage card1");	

  //p->SetCurDir(L"SDMMC");
	
	SetTimer(GRAPHICMGR.GetWnd(),SDCARD_TIMEER,2*1000,SDCardTimerNaviPathProc);
	//

	return true;
}

bool CNaviPathListStatu::EvaluateClickEvent(const WCHAR* elementName)
{
	/*if (wcscmp(elementName,L"book_play") == 0)
		return playclick();*/
	 if (wcscmp(elementName,L"navipathlist_btn_listup") == 0)
		return upclick();
	else if (wcscmp(elementName,L"navipathlist_btn_listdown") == 0)
		return downclick();
	return false;
}

bool CNaviPathListStatu::EvaluateDBClickEvent(const WCHAR* elementName)
{
	if (wcscmp(elementName,L"listview_NaviPathList") == 0)
		return playclick();
	return false;
}


bool CNaviPathListStatu::playclick()
{
	
	
		CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_NaviPathList");
    	wstring  strPlayFile=pList->GetItemData(pList->GetListSelectedItem());
		if (FILE_TYPE!=pList->GetListItemType(pList->GetListSelectedItem()))
		{
			return false ;
		}
		
		
		CStaticText* p = (CStaticText*)GRAPHICMGR.GetElement(L"txtnavipath");
		if (p)
			p->setvalue(strPlayFile.c_str());
		CMyReg   mReg;
		if (mReg.Open(HKEY_CURRENT_USER, TEXT("OEM\\APP")))
		mReg.SetSZ(L"GpsPath",strPlayFile.c_str(),strPlayFile.size());
		GRAPHICMGR.PostChange(L"navipath");

	return true;
}


bool CNaviPathListStatu::upclick()
{
	CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_NaviPathList");
	m_nIndexPos--;
	if(m_nIndexPos < 1)
	{
		m_nIndexPos = 1;
	}
	pList->SetCurPage(m_nIndexPos);
	GRAPHICMGR.SetUpdateElements(L"listview_NaviPathList",L"none");


	return true;
}

bool CNaviPathListStatu::downclick()
{
	
	//GRAPHICMGR.AllElementUpdate();
	CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_NaviPathList");
	m_nIndexPos++;
	if(m_nIndexPos >= pList->GetTotalPage())
	{
		m_nIndexPos = pList->GetTotalPage();
	}

	pList->SetCurPage(m_nIndexPos);
	GRAPHICMGR.SetUpdateElements(L"listview_NaviPathList",L"none");

	return true;
}

